package com.crm.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.crm.entity.Netaskers;


public interface NetaskersRepository extends JpaRepository<Netaskers, Integer>,JpaSpecificationExecutor<Netaskers>{

	@Query(value="SELECT  n.net_asker_id from netakers n WHERE n.user_id =:userid",nativeQuery=true)
	public Integer getnetid(String userid);
	
	//获得当前操作的网络咨询师下的学生总人数
		@Query(value="select count(*) from student where net_asker_id=?1",nativeQuery=true)
		Integer StuCount(Integer netAskerId);
		
		//通过咨询师id得到相应学生的id
		@Query(value="select stuid from student where net_asker_id=?1",nativeQuery=true)
		List<String> StuId(Integer netAskerId);
		
		//改变分配状态
		@Modifying
		@Query(value="update netakers set change_state=?1 where net_asker_id=?2 ",nativeQuery=true)
		Integer status(String status,Integer netAskerId);
		
        //通过用户id查询网络咨询师id
		@Query(value="SELECT net_asker_id from netakers WHERE user_id=?1",nativeQuery=true)
        Integer netId(String userId);
		//查询自动分配已开启的网络咨询师(做定时任务用)
		@Query(value="select * from netakers where change_state='是' ",nativeQuery=true)
		List<Netaskers> StartAuto();
		//根据用户id查询网络咨询师是否进行了学生的分配
		@Query(value="select *  from netakers where net_asker_id=?1",nativeQuery=true)
		List<Netaskers> ChaFenPei(Integer netAskerId);
}
